//  Inside Microsoft Exchange 2007 Web Services 
//  Chapter 15
//
//  Copyright (c) 2007 David Sterling, Ben Spain, Mark Taylor, Huw Upshall, Michael Mainer.  
//  All rights reserved.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using ProxyHelpers.EWS;

namespace CreateOneHundredFolders
{
    class Program
    {
        static void Main(string[] args)
        {
            ExchangeServiceBinding binding = new ExchangeServiceBinding();
            binding.Url = @"https://yourServer/ews/Exchange.asmx";
            binding.Credentials = new NetworkCredential(
                "username",
                "password",
                "domain");

            CreateOneHundredFolders(binding);
        }

        /// <summary>
        /// Creates one hundred folders in the inbox (Listing 15-1)
        /// </summary>
        /// <param name="binding">Binding to use for request</param>
        /// 
        public static void CreateOneHundredFolders(
                        ExchangeServiceBinding binding)
        {
            CreateFolderType request = new CreateFolderType();
            DistinguishedFolderIdType inbox = new DistinguishedFolderIdType();
            inbox.Id = DistinguishedFolderIdNameType.inbox;
            request.ParentFolderId = new TargetFolderIdType();
            request.ParentFolderId.Item = inbox;
            BaseFolderType[] foldersToCreate = new BaseFolderType[100];
            for (int folderIndex = 0; folderIndex < 100; folderIndex++)
            {
                FolderType folder = new FolderType();
                folder.DisplayName = "Folder_" + folderIndex.ToString();
                foldersToCreate[folderIndex] = folder;
            }
            request.Folders = foldersToCreate;
            binding.CreateFolder(request);
        }
   }
}
